package com.five.community.service.impl;

import com.five.community.bean.Village;
import com.five.community.mapper.VillageMapper;
import com.five.community.service.VillageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VillageServiceImpl implements VillageService {

    @Autowired
    private VillageMapper villageMapper;
    @Override
    public List<Village> selectAll() throws Exception {
        return villageMapper.selectAll();
    }

    @Override
    public long selectIdByName(String name) throws Exception {
        return villageMapper.selectIdByName(name);
    }

    @Override
    public List<Village> selectByName(String name) throws Exception {
        return villageMapper.selectByName(name);
    }

    @Override
    public void insert(Village village) throws Exception {
        villageMapper.insert(village);
    }

    @Override
    public Village selectById(long id) throws Exception {
        return villageMapper.selectById(id);
    }

    @Override
    public void update(Village village) throws Exception {
        villageMapper.update(village);
    }

    @Override
    public void delete(long id) throws Exception {
        villageMapper.delete(id);
    }

    @Override
    public PageInfo<Village> getPageInfo(int pageNum,int pageSize) throws Exception {
        //先初始化模型在查询信息顺序不能颠倒
        //初始化分页插件模型
        PageHelper.startPage(pageNum,pageSize);
        //查询所有信息获得列表集合
        List<Village> villages = villageMapper.selectAll();
        //分页模型加入数据
        PageInfo<Village> pageInfo = new PageInfo<>(villages);
        //返回分页模型
        return pageInfo;
    }


}
